package com.cyanite.playlv2.widget;

import com.cyanite.playlv2.R;
import com.cyanite.playlv2api.types.Group;
import com.cyanite.playlv2api.types.User;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SecretFollowsAdapter extends BaseAdapter {

    private Group<User> mUsers;
    private LayoutInflater mInflater;
    private int mLayoutToInflate;

    public SecretFollowsAdapter(Context context, Group<User> users) {
        mUsers = users;
        mInflater = LayoutInflater.from(context);
        mLayoutToInflate = R.layout.checkin_list_item;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

       if (convertView == null) {
            convertView = mInflater.inflate(mLayoutToInflate, null);
            holder = new ViewHolder();
            holder.mPhoto = (ImageView) convertView.findViewById(R.id.photo);
            holder.mName = (TextView) convertView.findViewById(R.id.firstLine);
            holder.mDate = (TextView) convertView.findViewById(R.id.secondLine);
            holder.mNull = (TextView) convertView.findViewById(R.id.timeTextView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.mName.setText(mUsers.get(position).getUserName());
        holder.mDate.setText(mUsers.get(position).getDate());
        holder.mNull.setVisibility(View.GONE);

        return convertView;
    }

    public interface ButtonRowClickHandler {
        public void onBtnClickSecretDetail(User user);
    }

    static class ViewHolder {
        ImageView mPhoto;
        TextView mName;
        TextView mDate;
        TextView mNull;
    }

    @Override
    public int getCount() {
        return mUsers.size();
    }

    @Override
    public Object getItem(int position) {
        return mUsers.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
}
